package com.qidianit.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.mes.common.Result;
import com.qidianit.mes.pojo.pro.ProductionOrderBom;
import com.qidianit.mes.pro.mapper.ProductionOrderBomMapper;
import com.qidianit.mes.pro.service.ProductionOrderBomService;
import com.qidianit.mes.sys.mapper.UnitMapper;
import com.qidianit.mes.vo.ProductionOrderBomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Package Path: com.qidianit.mes.pro.service.impl
 * Author: Alhz
 * Description:
 * Date: 2025/9/22 20:19
 */
@Service
public class ProductionOrderBomServiceImpl implements ProductionOrderBomService {
    @Autowired
    private ProductionOrderBomMapper productionOrderBomMapper;

    @Autowired
    private UnitMapper unitMapper;


    /**
     * 分页查询
     * @param productionOrderId
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public Result selectByProductionOrderId(Long productionOrderId, int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<ProductionOrderBomVo> productionOrderBomVoList = productionOrderBomMapper.selectByProductionOrderId(productionOrderId);

        PageInfo pageInfo = new PageInfo(productionOrderBomVoList);
        return Result.success(pageInfo);
    }

    @Override
    public Result addProductionOrderBom(ProductionOrderBom productionOrderBom) {
        productionOrderBom.setCreateTime(LocalDateTime.now());
        productionOrderBom.setUpdateTime(LocalDateTime.now());
        productionOrderBom.setDeleteFlag(0);
        return Result.success(productionOrderBomMapper.addProductionOrderBom(productionOrderBom));
    }

    @Override
    public Result updateProductionOrderBom(ProductionOrderBom productionOrderBom) {
        System.out.println("*****************************");
        System.out.println(productionOrderBom);
        productionOrderBom.setUpdateTime(LocalDateTime.now());
        return Result.success(productionOrderBomMapper.updateProductionOrderBom(productionOrderBom));
    }


    @Override
    public Result batchDeleteProductionOrderBom(Long[] ids) {
        return Result.success(productionOrderBomMapper.batchDeleteProductionOrderBom(ids));
    }

    @Override
    public Result selectByPrimaryKey(Long id) {
        return Result.success(productionOrderBomMapper.selectByPrimaryKey(id));
    }



}
